package com.aef.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
	private final static SimpleDateFormat sdfTime = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");

	public static String getCurrentDate() {
		String format = "yyyyMMdd";
		Date date = new Date();
		date.setTime(System.currentTimeMillis());
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}

	/**
	 * 获取YYYY-MM-DD HH:mm:ss格式
	 * 
	 * @return
	 */
	public static String getTime() {
		return sdfTime.format(new Date());
	}
	/**
	 * 时间戳转data
	 * @param timestr
	 * @return
	 * @throws ParseException
	 */
	public static Date getStringSwitchData(String timestr) throws ParseException{
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
		Long time=new Long(timestr);  
		String d = format.format(time*1000);  
		Date date=format.parse(d);  
		return date;
	}
	/**
	 * string转data
	 * @param timestr
	 * @return
	 * @throws ParseException
	 */
	public static Date getStrSwitchData(String timestr) throws ParseException{
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");  
		Date date = format.parse(timestr);
		return date;
	}

}
